home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November A / PCWK1103A.iso / ABBYY FineReader 7.0 PRO / data1.cab / gs_init.ps < prev    next >
Text File  |  2002-04-16  |  62KB  |  1,883 lines

  1. % (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_init.ps,v 1.40.2.9 2002/04/15 06:49:43 giles Exp $
  14. % Initialization file for the interpreter.
  15. % When this is run, systemdict is still writable.
  16.  
  17. % Comment lines of the form
  18. %    %% Replace <n> <file(s)>
  19. % indicate places where the next <n> lines should be replaced by
  20. % the contents of <file(s)>, when creating a single merged init file.
  21.  
  22. % The interpreter can call out to PostScript code.  All procedures
  23. % called in this way, and no other procedures defined in these
  24. % initialization files, have names that begin with %, e.g.,
  25. % (%Type1BuildChar) cvn.
  26.  
  27. % Check the interpreter revision.  NOTE: the interpreter code requires
  28. % that the first non-comment token in this file be an integer.
  29. 705
  30. dup revision ne
  31.  { (gs: Interpreter revision \() print revision 10 string cvs print
  32.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  33.    (\).\n) print flush null 1 .quit
  34.  }
  35. if pop
  36.  
  37. % Acquire userdict, and set its length if necessary.
  38. /userdict where
  39.  { pop userdict maxlength 0 eq }
  40.  { true }
  41. ifelse
  42. systemdict exch
  43.  {        % userdict wasn't already set up by iinit.c.
  44.    dup /userdict
  45.    currentdict dup 200 .setmaxlength        % userdict
  46.    .forceput            % userdict is local, systemdict is global
  47.  }
  48. if begin
  49.  
  50. % Define dummy local/global operators if needed.
  51. systemdict /.setglobal known
  52.  { true .setglobal
  53.  }
  54.  { /.setglobal { pop } bind def
  55.    /.currentglobal { false } bind def
  56.    /.gcheck { pop false } bind def
  57.  }
  58. ifelse
  59.  
  60. % Define .languagelevel if needed.
  61. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  62.  
  63. % Optionally choose a default paper size other than U.S. letter.
  64. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  65.  
  66. % Turn on array packing for the rest of initialization.
  67. true setpacking
  68.  
  69. % Define the old MS-DOS EOF character as a no-op.
  70. % This is a hack to get around the absurd habit of MS-DOS editors
  71. % of adding an EOF character at the end of the file.
  72. <1a> cvn { } def
  73.  
  74. % Acquire the debugging flags.
  75. currentdict /DEBUG known   /DEBUG exch def
  76.   /VMDEBUG
  77.     DEBUG {{print mark
  78.             systemdict /level2dict known
  79.          { .currentglobal dup false .setglobal vmstatus
  80.            true .setglobal vmstatus 3 -1 roll pop
  81.            6 -2 roll pop .setglobal
  82.          }
  83.          { vmstatus 3 -1 roll pop
  84.          }
  85.         ifelse usertime 16#fffff and counttomark
  86.           { ( ) print (           ) cvs print }
  87.         repeat pop
  88.         ( ) print systemdict length (    ) cvs print
  89.         ( ) print countdictstack (  ) cvs print
  90.         ( <) print count (    ) cvs print (>\n) print flush
  91.       }}
  92.       {{pop
  93.       }}
  94.      ifelse
  95.   def
  96.  
  97. currentdict /BATCH known   /BATCH exch def
  98. currentdict /DELAYBIND known   /DELAYBIND exch def
  99. currentdict /DISKFONTS known   /DISKFONTS exch def
  100. currentdict /DOINTERPOLATE .knownget { /INTERPOLATE exch def } if
  101. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  102. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  103. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  104. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  105. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  106. currentdict /NOBIND known   /NOBIND exch def
  107. /.bind /bind load def
  108. NOBIND { /bind { } def } if
  109. currentdict /NOCACHE known   /NOCACHE exch def
  110. currentdict /NOCCFONTS known   /NOCCFONTS exch def
  111. currentdict /NOCIE known   /NOCIE exch def
  112. currentdict /NODISPLAY known   not /DISPLAYING exch def
  113. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  114. currentdict /NOCIDFONTMAP known /NOCIDFONTMAP exch def
  115. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  116. currentdict /NOGC known   /NOGC exch def
  117. currentdict /NOINTERPOLATE .knownget { /INTERPOLATE exch not def } if
  118. currentdict /NOPAGEPROMPT known   /NOPAGEPROMPT exch def
  119. currentdict /NOPAUSE known   /NOPAUSE exch def
  120. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  121. currentdict /NOPROMPT known   /NOPROMPT exch def
  122. % The default value of ORIENT1 is true, not false.
  123. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  124. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  125. currentdict /OUTPUTFILE known    % obsolete
  126.  { /OutputFile /OUTPUTFILE load def
  127.    currentdict /OUTPUTFILE .undef
  128.  } if
  129. currentdict /QUIET known   /QUIET exch def
  130. % DELAYSAFER is effectively the same as newer NOSAFER
  131. currentdict /DELAYSAFER known { /DELAYSAFER true def /NOSAFER true def } if
  132. currentdict /PARANOIDSAFER known /PARANOIDSAFER exch def
  133. /SAFER currentdict /NOSAFER known {
  134.   false
  135. } {
  136.   currentdict /SAFER known PARANOIDSAFER or
  137. }
  138. ifelse def
  139. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  140. currentdict /STRICT known   /STRICT exch def
  141. currentdict /TTYPAUSE known   /TTYPAUSE exch def
  142. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  143.  
  144. % Acquire environment variables.
  145. currentdict /DEVICE known not
  146.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  147.  
  148. (START) VMDEBUG
  149.  
  150. % Open the standard files, so they will be open at the outermost save level.
  151. (%stdin) (r) file pop
  152. (%stdout) (w) file pop
  153. (%stderr) (w) file pop
  154.  
  155. /.currentuserparams where {
  156.   pop mark
  157.     % The Adobe implementations appear to have very large maximum
  158.     % stack sizes.  This turns out to actually make a difference,
  159.     % since some badly-behaved files include extremely long procedures,
  160.     % or construct huge arrays on the operand stack.
  161.     % We reset the stack sizes now so that we don't have to worry
  162.     % about overflowing the (rather small) built-in stack sizes
  163.     % during initialization.
  164.   /MaxDictStack 500
  165.   /MaxExecStack 5000
  166.   /MaxOpStack 50000
  167.   .dicttomark .setuserparams
  168. } if
  169.  
  170. % Define a procedure for skipping over an unneeded section of code.
  171. % This avoids allocating space for the skipped procedures.
  172. % We can't use readline, because that imposes a line length limit.
  173. /.skipeof    % <string> .skipeof -
  174.  { currentfile exch 1 exch .subfiledecode flushfile
  175.  } .bind def
  176.  
  177. % Define procedures to assist users who don't read the documentation.
  178. userdict begin
  179. /help
  180.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  181.    print flush
  182.  } .bind def
  183. end
  184.  
  185. % Define =string, which is used by some PostScript programs even though
  186. % it isn't documented anywhere.
  187. % Put it in userdict so that each context can have its own copy.
  188. userdict /=string 256 string put
  189.  
  190. % Print the greeting.
  191.  
  192. /printgreeting
  193.  { mark
  194.    product (Ghostscript) search
  195.     { pop pop pop
  196.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  197.     }
  198.     { pop
  199.     }
  200.    ifelse
  201.    (\n) copyright
  202.    (\)\n) revisiondate 10 mod revisiondate 10 idiv 10 mod (-)
  203.    revisiondate 100 idiv 10 mod revisiondate 1000 idiv 10 mod (-)
  204.    revisiondate 10000 idiv ( \()
  205.    revision 10 mod
  206.    revision 100 mod 10 idiv (.)
  207.    revision 100 idiv ( )
  208.    product
  209.    counttomark
  210.     { (%stdout) (w) file exch 0 .writecvp
  211.     } repeat pop
  212.  } .bind def
  213.  
  214. QUIET not { printgreeting flush } if
  215.  
  216. % Define a special version of def for making operator procedures.
  217. /obind {    % <name> <proc> obind <name> <oper>
  218.   1 index exch .makeoperator
  219. } .bind def
  220. /odef {        % <name> <proc> odef -
  221.   1 index exch .makeoperator def
  222. } .bind def
  223.  
  224. % Define a special version of def for storing local objects into global
  225. % dictionaries.  Like .forceput, this exists only during initialization.
  226. /.forcedef {        % <key> <value> .forcedef -
  227.   currentdict 3 1 roll .forceput
  228. } .bind odef
  229.  
  230. % Define procedures for accessing variables in systemdict and userdict
  231. % regardless of the contents of the dictionary stack.
  232. /.systemvar {        % <name> .systemvar <value>
  233.   //systemdict exch get
  234. } .bind odef
  235. /.userdict {        % - .userdict <dict>
  236.   /userdict .systemvar
  237. } .bind odef
  238. /.uservar {        % <name> .uservar <value>
  239.   .userdict exch get
  240. } .bind odef
  241.  
  242. % If we're delaying binding, remember everything that needs to be bound later.
  243. DELAYBIND NOBIND not and
  244.  { .currentglobal false .setglobal
  245.    systemdict /.delaybind 1500 array .forceput
  246.    .setglobal
  247.    userdict /.delaycount 0 put
  248.     % When we've done the delayed bind, we want to stop saving.
  249.     % Detect this by the disappearance of .delaybind.
  250.    /bind
  251.     { /.delaybind .systemvar dup length 0 ne
  252.        { .delaycount 2 index put
  253.          .userdict /.delaycount .delaycount 1 add put
  254.        }
  255.        { pop .bind
  256.        }
  257.       ifelse
  258.     } .bind def
  259.  } if
  260.  
  261. %**************** BACKWARD COMPATIBILITY ****************
  262. /hwsizedict mark /HWSize null .dicttomark readonly def
  263. /copyscanlines {        % <device> <y> <string> copyscanlines <substr>
  264.   0 3 1 roll 3 index //hwsizedict .getdeviceparams
  265.   exch pop exch pop aload pop 3 2 roll
  266.   0 exch null exch .getbitsrect exch pop
  267. } bind odef
  268. currentdict /hwsizedict .undef
  269. /getdeviceprops
  270.  { null .getdeviceparams
  271.  } bind odef
  272. /.putdeviceprops
  273.  { null true counttomark 1 add 3 roll .putdeviceparams
  274.    dup type /booleantype ne
  275.     { dup mark eq { /unknown /rangecheck } if
  276.       counttomark 4 add 1 roll cleartomark pop pop pop
  277.       /.putdeviceprops load exch signalerror
  278.     }
  279.    if
  280.  } bind odef
  281. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  282. /.setfilladjust { dup .setfilladjust2 } bind odef
  283. /.writecvs { 0 .writecvp } bind odef
  284. %**************** DEPRECATED PROCEDURES ****************
  285. %**************** DO NOT USE THESE IN NEW CODE ****************
  286. /max { .max } bind def        % use .max instead
  287. /min { .min } bind def        % use .min instead
  288. /unread /.unread load def    % use .peekstring instead
  289. %**************** END OF BACKWARD COMPATIBILITY SECTION ****************
  290.  
  291. % Define predefined procedures substituting for operators,
  292. % in alphabetical order.
  293.  
  294. userdict /#copies 1 put
  295. % Adobe implementations don't accept /[ or /], so we don't either.
  296. ([) cvn
  297.     /mark load def
  298. (]) cvn
  299.     {counttomark array astore exch pop} odef
  300. % .beginpage is redefined if setpagedevice is present.
  301. /.beginpage { } odef
  302. % In LanguageLevel 3, copypage erases the page.
  303. /copypage {
  304.     .languagelevel 3 ge
  305.     dup { 0 } { 1 } ifelse .endpage {
  306.       .currentnumcopies 1 index .outputpage
  307.       (>>copypage, press <return> to continue<<\n) .confirm
  308.       dup { erasepage } if
  309.     } if pop .beginpage
  310. } odef
  311. /currentmatrix {
  312.     .currentmatrix 6 index astore pop
  313. } odef
  314. % .currentnumcopies is redefined in Level 2.
  315. /.currentnumcopies { #copies } odef
  316. /setcolorscreen where { pop        % not in all Level 1 configurations
  317.    /currentcolorscreen
  318.     { .currenthalftone
  319.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  320.          { 3 copy 6 copy }            % screen
  321.          { }                % colorscreen
  322.        }
  323.       exch get exec
  324.     } odef
  325. } if
  326. /currentscreen
  327.     { .currenthalftone
  328.        { { 60 exch 0 exch }            % halftone - not possible
  329.          { }                % screen
  330.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  331.        }
  332.       exch get exec
  333.     } odef
  334. /.echo /echo load def
  335. userdict /.echo.mode true put
  336. /echo    {dup /.echo.mode exch store .echo} odef
  337. /eexec {
  338.     % Rebind .currentresourcefile if it is the source for the eexec.
  339.   dup 55665 //filterdict /eexecDecode get exec
  340.   cvx exch .currentresourcefile eq
  341.   //systemdict begin { {exec} .execasresource } { exec } ifelse
  342.     % Only pop systemdict if it is still the top element,
  343.     % because this is apparently what Adobe interpreters do.
  344.   currentdict //systemdict eq { end } if
  345. } odef
  346. % .endpage is redefined if setpagedevice is present.
  347. /.endpage { 2 ne } odef
  348. % erasepage mustn't use gsave/grestore, because we call it before
  349. % the graphics state stack has been fully initialized.
  350. /erasepage
  351.     { /currentcolor where
  352.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  353.        { /currentcmykcolor where
  354.           { pop currentcmykcolor { setcmykcolor } }
  355.           { currentrgbcolor { setrgbcolor } }
  356.          ifelse
  357.        }
  358.       ifelse 1 setgray .fillpage exec
  359.     } odef
  360. % To satisfy the Genoa FTS, executive must be a procedure, not an operator.
  361. /executive
  362.     { { prompt
  363.          { (%statementedit) (r) file } stopped
  364.          { pop pop $error /errorname get /undefinedfilename eq
  365.         { .clearerror exit } if        % EOF
  366.            handleerror null        % ioerror??
  367.          }
  368.         if
  369.         cvx { .runexec } execute
  370.       } loop
  371.     } bind def
  372. /filter
  373.     { //filterdict 1 index .knownget
  374.        { exch pop exec }
  375.        { /filter load /undefined signalerror }
  376.       ifelse
  377.     } odef
  378. /handleerror
  379.     { /errordict .systemvar /handleerror get exec } bind def
  380. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  381. /identmatrix
  382.     { dup 0 //identmatrix putinterval } odef
  383. /languagelevel 1 def        % gs_lev2.ps may change this
  384. /makeimagedevice { false makewordimagedevice } odef
  385. /matrix    { 6 array identmatrix } odef
  386. /pathbbox
  387.     { false .pathbbox
  388.     } odef
  389. % .promptmsg is redefined if the interpreter includes readline support.
  390. /.promptmsg {
  391.     (GS) print
  392.     count 0 ne { (<) print count =only } if
  393.     (>) print flush
  394. } bind def
  395. /prompt    { flush flushpage NOPROMPT not { .promptmsg } if } bind def
  396. /pstack    { 0 1 count 3 sub { index == } for } bind def
  397. /putdeviceprops
  398.     { .putdeviceprops { erasepage } if } odef
  399. /quit    { /quit load 0 .quit } odef
  400. /run    { dup type /filetype ne { (r) file } if
  401.         % We must close the file when execution terminates,
  402.         % regardless of the state of the stack,
  403.         % and then propagate an error, if any.
  404.       cvx .runexec
  405.     } odef
  406. % Execute a file.
  407. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  408. % we detect that here, since we need to handle this even if we start out
  409. % without job control in effect.
  410. %
  411. % What we push on the e-stack is the following to be executed in this order:
  412. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  413. /.runexec1 {        % <file|fileproc> .runexec1 -
  414.   dup type /filetype ne { cvx exec } if
  415.   cvx null 2 .stopped
  416.     % If we got back here from a startjob, just keep going.
  417.     % startjob replaces the null on the o-stack with a procedure
  418.     % to be executed when we get back here.
  419.   dup null ne { exec true } { pop false } ifelse
  420. } bind def
  421. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  422.   exch {
  423.     .runexec
  424.   } {
  425.     dup type /filetype ne { cvx exec } if
  426.     closefile
  427.   } ifelse
  428. } bind def
  429. /.runexec {        % <file|fileproc> .runexec -
  430.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  431. } bind def
  432. % The following is only for compatibility with Adobe interpreters.
  433. /setdash {
  434.     1 index length 11 gt { /setdash load /limitcheck signalerror } if
  435.     //setdash
  436. } odef
  437. /setdevice
  438.     { .setdevice { erasepage } if } odef
  439. /setlinecap {
  440.     dup 2 gt { /setlinecap load /rangecheck signalerror } if
  441.     .setlinecap
  442. } odef
  443. /setlinejoin {
  444.     dup 2 gt { /setlinejoin load /rangecheck signalerror } if
  445.     .setlinejoin
  446. } odef
  447. /setmatrix {
  448.     dup aload pop .setmatrix pop
  449. } odef
  450. /showpage {
  451.     0 .endpage .doneshowpage {
  452.       .currentnumcopies true .outputpage
  453.       (>>showpage, press <return> to continue<<\n) .confirm
  454.       erasepage
  455.     } if initgraphics .beginpage
  456. } odef
  457. % Code output by Adobe Illustrator relies on the fact that
  458. % `stack' is a procedure, not an operator!!!
  459. /stack    { 0 1 count 3 sub { index = } for } bind def
  460. /start    { BATCH { null 0 .quit } { executive } ifelse } def
  461. % Internal uses of stopped that aren't going to do a stop if an error occurs
  462. % should use .internalstopped to avoid setting newerror et al.
  463. /.internalstopped { null 1 .stopped null ne } bind def
  464. /store {    % Don't alter operands before completing.
  465.     1 index where { 2 index 2 index put pop pop } { def } ifelse
  466. } odef
  467. /.typenames mark .typenames counttomark packedarray exch pop def
  468. /type {
  469.     //.typenames .type
  470. } odef
  471. currentdict /.typenames .undef
  472. % When running in Level 1 mode, this interpreter is supposed to be
  473. % compatible with PostScript "version" 54.0 (I think).
  474. /version (54.0) readonly def
  475. /.wheredict 10 dict def
  476. /.where /where load def
  477. /where {
  478.     //.wheredict 1 index .knownget { exec } { .where } ifelse
  479. } odef
  480.  
  481. % internaldict is defined in systemdict, but the dictionary is allocated
  482. % in local VM.  However, the procedure must be global, since it is an
  483. % "operator" and must be bind-able into global procedures.
  484. % We make a procedure for creating it, since we must create a new one
  485. % for each context with private local VM.
  486. /.makeinternaldict {
  487.   .currentglobal true .setglobal
  488.     [ /dup .systemvar 1183615869 /eq .systemvar
  489.     [ /pop .systemvar null ] cvx
  490.     false .setglobal
  491.     dup 1 10 dict .forceput    % proc is global, dict is local
  492.     true .setglobal
  493.     [ /internaldict /cvx .systemvar /invalidaccess /signalerror cvx ] cvx
  494.       /ifelse .systemvar
  495.     ] cvx executeonly
  496.   exch .setglobal
  497. } odef
  498. systemdict /internaldict dup .makeinternaldict .makeoperator
  499. .forceput        % proc is local, systemdict is global
  500. % Move superexec to internaldict if superexec is defined.
  501. currentdict /superexec .knownget {
  502.   1183615869 internaldict /superexec 3 -1 roll put
  503.   currentdict /superexec .undef
  504. } if
  505.  
  506. % Define some additional built-in procedures (beyond the ones defined by
  507. % the PostScript Language Reference Manual).
  508. % Warning: these are not guaranteed to stay the same from one release
  509. % to the next!
  510. /concatstrings    %    (str1) (str2) concatstrings (str1str2)
  511.     { exch dup length 2 index length add string    % str2 str1 new
  512.       dup dup 4 2 roll copy        % str2 new new new1
  513.       length 4 -1 roll putinterval
  514.     } bind def
  515. /copyarray
  516.     { dup length array copy } bind def
  517. % Copy a dictionary per the Level 2 spec even in Level 1.
  518. /.copydict        % <fromdict> <todict> .copydict <todict>
  519.     { dup 3 -1 roll { put dup } forall pop } bind def
  520. /copystring
  521.     { dup length string copy } bind def
  522. /findlibfile {
  523.     .libfile { dup .filename pop exch true } { false } ifelse
  524. } odef
  525. /.growdictlength    % get size for growing a dictionary
  526.     { length 3 mul 2 idiv 1 add
  527.     } bind def
  528. /.growdict        % grow a dictionary
  529.     { dup .growdictlength .setmaxlength
  530.     } bind def
  531. /.growput        % put, grow the dictionary if needed
  532.     { 2 index length 3 index maxlength eq
  533.        { 3 copy pop known not { 2 index .growdict } if
  534.        } if
  535.       put
  536.     } bind def
  537. % .localvmarray may be an operator: see zsysvm.c.
  538. /.localvmarray where {
  539.   pop
  540. } {
  541.   /.localvmarray {
  542.     .currentglobal false .setglobal
  543.     exch array exch .setglobal
  544.   } bind def
  545. } ifelse
  546. /.localvmdict where {
  547.   pop
  548. } {
  549.   /.localvmdict {
  550.     .currentglobal false .setglobal
  551.     exch dict exch .setglobal
  552.   } bind def
  553. } ifelse
  554. /.packtomark
  555.     { counttomark packedarray exch pop } bind def
  556. /ppstack
  557.     { 0 1 count 3 sub { index === } for } bind def
  558. /runlibfile
  559.     {        % We don't want to bind 'run' into this procedure,
  560.             % since run may get redefined.
  561.       findlibfile
  562.        { exch pop /run .systemvar exec }
  563.        { /undefinedfilename signalerror }
  564.       ifelse
  565.     } bind def
  566. /selectdevice
  567.     { finddevice setdevice .setdefaultscreen } bind def
  568. /signalerror        % <object> <errorname> signalerror -
  569.     { /errordict .systemvar exch get exec } bind def
  570.  
  571. % Define the =[only] procedures.  Also define =print,
  572. % which is used by some PostScript programs even though
  573. % it isn't documented anywhere.
  574. /write=only {
  575.     .writecvs
  576. } bind def
  577. /write= {
  578.     1 index exch write=only (\n) writestring
  579. } bind def
  580. /=only    { (%stdout) (w) file exch write=only } bind def
  581. /=    { =only (\n) print } bind def
  582. /=print    /=only load def
  583. % Temporarily define == as = for the sake of runlibfile0.
  584. /== /= load def
  585.  
  586. % The following procedures are documented.
  587. /copydevice {        % <device> copydevice <newdevice>
  588.   false .copydevice2
  589. } odef
  590. /finddevice {        % <devicename> finddevice <device>
  591.   /devicedict .systemvar exch get
  592.   dup 1 get null eq {
  593.         % This is the first request for this type of device.
  594.         % Create a default instance now.
  595.         % Stack: [proto null]
  596.     .currentglobal true .setglobal exch
  597.     dup dup 0 get copydevice 1 exch put
  598.     exch .setglobal
  599.   } if 1 get
  600. } bind def
  601. /findprotodevice {    % <devicename> findprotodevice <protodevice>
  602.   /devicedict .systemvar exch get 0 get
  603. } bind def
  604.  
  605. % Run a resource file.  This allows us to distinguish resource objects
  606. % from objects coming from input files.
  607. userdict /.currentresourcefile null put
  608. /.execasresource {    % <file> <proc|runfile> .execasresource -
  609.   /stopped .systemvar
  610.   /.currentresourcefile .uservar
  611.         % Stack: file proc -stopped- currfile
  612.   .userdict /.currentresourcefile 5 index cvlit put
  613.   2 .execn        % stopped <file>
  614.   .userdict /.currentresourcefile 3 -1 roll put
  615.   { stop } if
  616. } bind def
  617. /.runresource {        % <file> .runresource -
  618.   { /run .systemvar exec } .execasresource
  619. } bind def
  620.  
  621. % Define procedures for getting and setting the current device resolution.
  622.  
  623. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  624.  { 2 copy mark exch null .dicttomark .getdeviceparams
  625.    dup mark eq        % if true, not found
  626.     { pop dup /undefined signalerror }
  627.     { 5 1 roll pop pop pop pop }
  628.    ifelse
  629.  } bind def
  630. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  631.  { currentdevice /HWResolution gsgetdeviceprop
  632.  } bind def
  633. /gssetresolution    % <[xres yres]> gssetresolution -
  634.  { 2 array astore mark exch /HWResolution exch
  635.    currentdevice copydevice putdeviceprops setdevice
  636.  } bind def
  637.  
  638. % Define auxiliary procedures needed for the above.
  639. /shellarguments        % -> shell_arguments true (or) false
  640.     { /ARGUMENTS where
  641.        { /ARGUMENTS get dup type /arraytype eq
  642.           { aload pop /ARGUMENTS null store true }
  643.           { pop false }
  644.          ifelse }
  645.        { false } ifelse
  646.     } bind def
  647. /.confirm {
  648.   DISPLAYING NOPAUSE not TTYPAUSE or and {
  649.     % Print a message (unless NOPAGEPROMPT or NOPROMPT is true)
  650.     % and wait for the user to type something.
  651.     % If the user just types a newline, flush it.
  652.     NOPAGEPROMPT NOPROMPT or { pop } { print flush } ifelse
  653.     .confirmread
  654.   } {
  655.     pop
  656.   } ifelse
  657. } bind def
  658. /.confirmread {
  659.   TTYPAUSE {
  660.     (/dev/tty) (r) file dup read pop pop closefile
  661.   } {
  662.     .echo.mode false echo
  663.     (%stdin) (r) file dup read {
  664.       dup (\n) 0 get eq { pop pop } { unread } ifelse
  665.     } {
  666.       pop
  667.     } ifelse echo
  668.   } ifelse
  669. } bind def
  670.  
  671. % Define the procedure used by .runfile, .runstdin and .runstring
  672. % for executing user input.
  673. % This is called with a procedure or executable file on the operand stack.
  674. /.execute {        % <obj> .execute <stopped>
  675.   stopped $error /newerror get and
  676.    { handleerror flush true } { false } ifelse
  677. } bind def
  678. /execute {        % <obj> execute -
  679.   .execute pop
  680. } odef
  681. % Define an execute analogue of runlibfile0.
  682. /execute0 {        % <obj> execute0 -
  683.   .execute { /execute0 cvx 1 .quit } if
  684. } bind def
  685. % Define the procedure that the C code uses for running files
  686. % named on the command line.
  687. /.runfile {
  688.   { runlibfile } execute0
  689. } def
  690. % Define the procedure that the C code uses for running piped input.
  691. % We don't use the obvious { (%stdin) run }, because we want the file to be
  692. % reopened if a startjob does a restore.
  693. /.runstdin {
  694.   { { (%stdin) (r) file cvx } .runexec } execute0
  695. } bind def
  696. % Define the procedure that the C code uses for running commands
  697. % given on the command line with -c.  We turn the string into a file so that
  698. % .runexec can do the right thing with a startjob.
  699. /.runstring {
  700.   .currentglobal exch true .setglobal
  701.   0 () .subfiledecode
  702.   exch .setglobal cvx { .runexec } execute0
  703. } bind def
  704. % Define the procedure that the C code uses to set up for executing
  705. % a string that may be received in pieces.
  706. /.runstringbegin {
  707.   .currentglobal true .setglobal
  708.   { .needinput } bind 0 () .subfiledecode
  709.   exch .setglobal cvx .runexec
  710. } bind def
  711.  
  712. % Define a special version of runlibfile that aborts on errors.
  713. /runlibfile0
  714.     { cvlit dup /.currentfilename exch def
  715.        { findlibfile not { stop } if }
  716.       stopped
  717.        { (Can't find \(or open\) initialization file ) print
  718.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  719.        } if
  720.       exch pop cvx stopped
  721.        { (While reading ) print .currentfilename print (:\n) print flush
  722.          handleerror /runlibfile0 1 .quit
  723.        } if
  724.     } bind def
  725. % Temporarily substitute it for the real runlibfile.
  726. /.runlibfile /runlibfile load def
  727. /runlibfile /runlibfile0 load def
  728.  
  729. % Create the error handling machinery.
  730. % Define the standard error handlers.
  731. % The interpreter has created the ErrorNames array.
  732. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  733.  {    % This is the handler that gets used for recursive errors,
  734.     % or errors outside the scope of a 'stopped'.
  735.    2 copy SHORTERRORS
  736.     { (%%[ Error: ) print =only flush
  737.       (; OffendingCommand: ) print =only ( ]%%) =
  738.     }
  739.     { (Unrecoverable error: ) print =only flush
  740.       ( in ) print = flush
  741.       count 2 gt
  742.        { (Operand stack:\n  ) print
  743.          count 1 sub -1 2 { (  ) print index =only flush } for
  744.      () = flush
  745.        } if
  746.     }
  747.    ifelse
  748.    -1 0 1 //ErrorNames length 1 sub
  749.     { dup //ErrorNames exch get 3 index eq
  750.        { not exch pop exit } { pop } ifelse
  751.     }
  752.    for exch pop .quit
  753.  } bind def
  754. /.errorhandler        % <command> <errorname> .errorhandler -
  755.   {        % Detect an internal 'stopped'.
  756.     1 .instopped { null eq { pop pop stop } if } if
  757.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  758.      { .unstoppederrorhandler
  759.      } if    % detect error recursion
  760.     $error /globalmode .currentglobal false .setglobal put
  761.     $error /.inerror true put
  762.     $error /newerror true put
  763.     $error exch /errorname exch put
  764.     $error exch /command exch put
  765.     $error /recordstacks get $error /errorname get /VMerror ne and
  766.      {        % Attempt to store the stack contents atomically.
  767.        count array astore dup $error /ostack 4 -1 roll
  768.        countexecstack array execstack $error /estack 3 -1 roll
  769.        countdictstack array dictstack $error /dstack 3 -1 roll
  770.        put put put aload pop
  771.      }
  772.      { $error /dstack .undef
  773.        $error /estack .undef
  774.        $error /ostack .undef
  775.      }
  776.     ifelse
  777.     $error /position currentfile status
  778.      { currentfile { fileposition } .internalstopped { pop null } if
  779.      }
  780.      {        % If this was a scanner error, the file is no longer current,
  781.         % but the command holds the file, which may still be open.
  782.        $error /command get dup type /filetype eq
  783.         { { fileposition } .internalstopped { pop null } if }
  784.         { pop null }
  785.        ifelse
  786.      }
  787.     ifelse put
  788.         % During initialization, we don't reset the allocation
  789.         % mode on errors.
  790.     $error /globalmode get $error /.nosetlocal get and .setglobal
  791.     $error /.inerror false put
  792.     stop
  793.   } bind def
  794. % Define the standard handleerror.  We break out the printing procedure
  795. % (.printerror) so that it can be extended for binary output
  796. % if the Level 2 facilities are present.
  797.   /.printerror
  798.    { $error begin
  799.        /command load errorname SHORTERRORS
  800.     { (%%[ Error: ) print =only flush
  801.       (; OffendingCommand: ) print =only
  802.       errorinfo dup null eq {
  803.         pop
  804.       } {
  805.         (;\nErrorInfo:) print
  806.         dup type /arraytype eq
  807.           { { ( ) print =only } forall }
  808.           { ( ) print =only }
  809.         ifelse
  810.       } ifelse
  811.           ( ]%%) = flush
  812.     }
  813.     { (Error: ) print ==only flush
  814.       ( in ) print ==only flush
  815.       errorinfo dup null eq {
  816.         pop
  817.       } {
  818.         (\nAdditional information: ) print ==only flush
  819.       } ifelse
  820.       .printerror_long
  821.     }
  822.        ifelse
  823.        .clearerror
  824.      end
  825.      flush
  826.     } bind def     
  827.   /.printerror_long            % long error printout,
  828.                     % $error is on the dict stack
  829.    {    % Push the (anonymous) stack printing procedure.
  830.     %  <heading> <==flag> <override-name> <stackname> proc
  831.        {
  832.      currentdict exch .knownget    % stackname defined in $error?
  833.      {
  834.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  835.        errordict exch .knownget    % overridename defined?
  836.        { 
  837.          exch pop exch pop exec    % call override with <stack>
  838.        }
  839.        { 
  840.          exch print exch        % print heading. stack <==flag> <stack>
  841.          1 index not { () = } if
  842.          { 1 index { (\n    ) } { (   ) } ifelse print
  843.            dup type /dicttype eq
  844.            {
  845.          (--dict:) print
  846.          dup rcheck {
  847.            dup length =only (/) print dup maxlength =only
  848.            dup wcheck not { ((ro)) print } if
  849.          } if
  850.          /gcheck where {
  851.            pop gcheck { ((G)) } { ((L)) } ifelse print
  852.          } {
  853.            pop
  854.          } ifelse (--) print
  855.            }
  856.            {
  857.          dup type /stringtype eq 2 index or
  858.          { ==only } { =only } ifelse
  859.            } ifelse
  860.          } forall
  861.          pop
  862.        }
  863.        ifelse            % overridden
  864.      }
  865.      { pop pop pop
  866.      }
  867.      ifelse                % stack known
  868.        }
  869.  
  870.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  871.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  872.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  873.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  874.        () =
  875.        pop    % printing procedure
  876.  
  877.        errorname /VMerror eq
  878.     { (VM status:) print mark vmstatus
  879.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  880.       cleartomark () =
  881.     } if
  882.  
  883.        .languagelevel 2 ge
  884.     { (Current allocation mode is ) print
  885.       globalmode { (global\n) } { (local\n) } ifelse print
  886.     } if
  887.  
  888.        .oserrno dup 0 ne
  889.     { (Last OS error: ) print
  890.       errorname /VMerror ne
  891.        { dup .oserrorstring { = pop } { = } ifelse }
  892.        { = }
  893.       ifelse
  894.     }
  895.     { pop
  896.     }
  897.        ifelse
  898.  
  899.        position null ne
  900.     { (Current file position is ) print position = }
  901.        if
  902.  
  903.    } bind def
  904. % Define a procedure for clearing the error indication.
  905. /.clearerror
  906.  { $error /newerror false put
  907.    $error /errorname null put
  908.    $error /errorinfo null put
  909.    0 .setoserrno
  910.  } bind def
  911.  
  912. % Define $error.  This must be in local VM.
  913. .currentglobal false .setglobal
  914. /$error 40 dict .forcedef    % $error is local, systemdict is global
  915.         % newerror, errorname, command, errorinfo,
  916.         % ostack, estack, dstack, recordstacks,
  917.         % binary, globalmode,
  918.         % .inerror, .nosetlocal, position,
  919.         % plus extra space for badly designed error handers.
  920. $error begin
  921.   /newerror false def
  922.   /recordstacks true def
  923.   /binary false def
  924.   /globalmode .currentglobal def
  925.   /.inerror false def
  926.   /.nosetlocal true def
  927.   /position null def
  928. end
  929. % Define errordict similarly.  It has one entry per error name,
  930. %   plus handleerror.  However, some astonishingly badly written PostScript
  931. %   files require it to have at least one empty slot.
  932. /errordict ErrorNames length 2 add dict
  933. .forcedef        % errordict is local, systemdict is global
  934. .setglobal        % contents of errordict are global
  935. errordict begin
  936.   ErrorNames
  937.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  938.    } forall
  939. % The handlers for interrupt and timeout are special; there is no
  940. % 'current object', so they push their own name.
  941.    { /interrupt /timeout }
  942.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  943.    } forall
  944. /handleerror
  945.  { /.printerror .systemvar exec
  946.  } bind def
  947. end
  948.  
  949. % Define the [write]==[only] procedures.
  950. /.dict 8 dict dup
  951. begin def
  952.   /.cvp {1 index exch 1 .writecvp} bind def
  953.   /.p {1 index exch writestring} bind def
  954.   /.p1 {2 index exch writestring} bind def
  955.   /.p2 {3 index exch writestring} bind def
  956.   /.print
  957.     { dup type .dict exch .knownget { exec } { .cvp } ifelse
  958.     } bind def
  959.   /arraytype
  960.     {dup rcheck
  961.       {() exch dup xcheck
  962.         {({) .p2
  963.          {exch .p1
  964.           1 index exch .print pop ( )} forall
  965.          (})}
  966.         {([) .p2
  967.          {exch .p1
  968.           1 index exch .print pop ( )} forall
  969.          (])}
  970.        ifelse exch pop .p}
  971.       {.cvp}
  972.      ifelse} bind def
  973.   /packedarraytype /arraytype load def
  974. {//.dict begin .print pop end}
  975.   bind
  976. end
  977.  
  978. /write==only exch def
  979. /write== {1 index exch write==only (\n) writestring} bind def
  980. /==only { (%stdout) (w) file exch write==only } bind def
  981. /== {==only (\n) print} bind def
  982.  
  983. % Define [write]===[only], an extension that prints dictionaries
  984. % in readable form and doesn't truncate strings.
  985. /.dict /write==only load 0 get dup length 2 add dict .copydict dup
  986. begin def
  987.   /dicttype
  988.     { dup rcheck
  989.        { (<< ) .p1
  990.           { 2 index 3 -1 roll .print pop ( ) .p1
  991.         1 index exch .print pop ( ) .p
  992.           }
  993.          forall (>>) .p
  994.        }
  995.        { .cvp
  996.        }
  997.       ifelse
  998.     } bind def
  999.   /stringtype
  1000.     { 1 index exch 2 .writecvp
  1001.     } bind def
  1002.  
  1003. {//.dict begin .print pop end}
  1004.   bind
  1005. end
  1006.  
  1007. /write===only exch def
  1008. /write=== {1 index exch write===only (\n) writestring} bind def
  1009. /===only { (%stdout) (w) file exch write===only } bind def
  1010. /=== { ===only (\n) print } bind def
  1011.  
  1012. (END PROCS) VMDEBUG
  1013.  
  1014. % Define the font directory.
  1015. /FontDirectory false .setglobal 100 dict true .setglobal
  1016. .forcedef        % FontDirectory is local, systemdict is global
  1017.  
  1018. % Define the encoding dictionary.
  1019. /EncodingDirectory 16 dict def    % enough for Level 2 + PDF standard encodings
  1020.  
  1021. % Define .findencoding.  (This is redefined in Level 2.)
  1022. /.findencoding
  1023.  { //EncodingDirectory exch get exec
  1024.  } bind def
  1025. /.defineencoding
  1026.  { //EncodingDirectory 3 1 roll put
  1027.  } bind def
  1028. % If we've got the composite font extensions, define findencoding.
  1029. % To satisfy the Genoa FTS, findencoding must be a procedure, not an operator.
  1030. /rootfont where { pop /findencoding { .findencoding } def } if
  1031.  
  1032. % Define .registerencoding.
  1033. % NOTE: the name registeredencodings is known to (initialized by and shared
  1034. % with) the interpreter.
  1035. /.registerencoding {    % <index> <array> .registerencoding -
  1036.     % Check that the array is indexable.
  1037.     % (It might still be a string, but then the .namestring will fail.)
  1038.   dup 0 0 getinterval pop
  1039.     % Check that all the elements of the array are names.
  1040.   dup { .namestring pop } forall
  1041.     % Do the store.
  1042.   //registeredencodings 2 index 2 index readonly put pop pop
  1043. } bind odef
  1044. systemdict /registeredencodings .undef
  1045.  
  1046. % Load StandardEncoding.
  1047. %% Replace 1 (gs_std_e.ps)
  1048. (gs_std_e.ps) dup runlibfile VMDEBUG
  1049.  
  1050. % Load ISOLatin1Encoding.
  1051. %% Replace 1 (gs_il1_e.ps)
  1052. (gs_il1_e.ps) dup runlibfile VMDEBUG
  1053.  
  1054. % Define stubs for the Symbol and Dingbats encodings.
  1055. % Note that the first element of the procedure must be the file name,
  1056. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  1057.  
  1058.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  1059. %% Replace 3 (gs_sym_e.ps)
  1060.   EncodingDirectory /SymbolEncoding
  1061.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  1062.   bind put
  1063.  
  1064.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  1065. %% Replace 3 (gs_dbt_e.ps)
  1066.   EncodingDirectory /DingbatsEncoding
  1067.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  1068.   bind put
  1069.  
  1070. (END FONTDIR/ENCS) VMDEBUG
  1071.  
  1072. % Construct a dictionary of all available devices.
  1073. % These are (read-only) device prototypes that can't be
  1074. % installed or have their parameters changed.  For this reason,
  1075. % the value in the dictionary is actually a 2-element writable array,
  1076. % to allow us to create a default instance of the prototype on demand.
  1077.  
  1078.     % Loop until the .getdevice gets a rangecheck.
  1079. errordict /rangecheck 2 copy get
  1080. errordict /rangecheck { pop stop } put    % pop the command
  1081.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  1082.   1 add dict  /devicedict 1 index def
  1083.   begin            % 2nd copy of count is on stack
  1084.    { dup .devicename exch
  1085.      dup wcheck { dup } { null } ifelse 2 array astore def
  1086.    } repeat
  1087.   end
  1088. put        % errordict /rangecheck
  1089. .clearerror
  1090. /devicenames devicedict { pop } forall devicedict length packedarray def
  1091.  
  1092. % Determine the default device.
  1093. /defaultdevice DISPLAYING
  1094.  { systemdict /DEVICE .knownget
  1095.     { devicedict 1 index known not
  1096.        { (Unknown device: ) print =
  1097.      flush /defaultdevice cvx 1 .quit
  1098.        }
  1099.       if
  1100.     }
  1101.     { 0 .getdevice .devicename
  1102.     }
  1103.    ifelse
  1104.  }
  1105.  { /nullpage
  1106.  }
  1107. ifelse
  1108. /.defaultdevicename 1 index def
  1109. finddevice    % make a copy
  1110. def
  1111. devicedict /Default devicedict .defaultdevicename get put
  1112.  
  1113. (END DEVS) VMDEBUG
  1114.  
  1115. % Define statusdict, for the benefit of programs
  1116. % that think they are running on a LaserWriter or similar printer.
  1117. %% Replace 1 (gs_statd.ps)
  1118. (gs_statd.ps) runlibfile
  1119.  
  1120. (END STATD) VMDEBUG
  1121.  
  1122. % Load the standard font environment.
  1123. %% Replace 1 (gs_fonts.ps)
  1124. (gs_fonts.ps) runlibfile
  1125.  
  1126. (END GS_FONTS) VMDEBUG
  1127.  
  1128. % Define the default halftone screen and BG/UCR functions now, so that
  1129. % it will bind in the original definitions of set[color]screen.
  1130. % We make this a procedure so we can call it again when switching devices.
  1131.  
  1132. % Use an ordered dither for low-resolution devices.
  1133. /.setloreshalftone {    % <dpi> .setloreshalftone -
  1134.     % The following 'ordered dither' spot function was contributed by
  1135.     % Gregg Townsend.  Thanks, Gregg!
  1136.    16.001 div 0            % not 16: avoids rounding problems
  1137.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1138.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1139.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1140.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1141.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1142.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1143.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1144.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1145.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1146.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1147.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1148.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1149.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1150.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1151.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1152.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1153.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1154.      > exch get 256 div
  1155.     }
  1156.    bind
  1157.         % Use correct, per-plane screens for CMYK devices only.
  1158.    //systemdict /setcolorscreen known processcolors 4 eq and
  1159.     { 3 copy 6 copy //setcolorscreen }
  1160.     { //setscreen }
  1161.    ifelse
  1162. } bind def
  1163. /.setloresscreen {    % <dpi> .setloresscreen -
  1164.   .setloreshalftone
  1165.   0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1166.   /setstrokeadjust where { pop true setstrokeadjust } if
  1167. } bind def
  1168. % Use a 45-degree spot screen for high-resolution devices.
  1169. /.sethireshalftone {    % <dpi> .sethireshalftone <doscreen>
  1170.     % According to information published by Hewlett-Packard,
  1171.     % they use a 60 line screen on 300 DPI printers and
  1172.     % an 85 line screen on 600 DPI printers.
  1173.     % However, we use a 106 line screen, which produces smoother-
  1174.     % looking shades but fewer of them (32 vs. 50).
  1175.     % 46 was suggested as a good frequency value for printers
  1176.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1177.     % Imagesetters need even higher frequency screens.
  1178.    //systemdict /DITHERPPI known
  1179.     { DITHERPPI
  1180.     }
  1181.     { dup cvi 100 idiv 15 .min
  1182.        {null 46 46 60 60 60 106 106 106 106 133 133 133 133 133 150}
  1183.       exch get
  1184.      }
  1185.    ifelse
  1186.    1 index 4.01 div .min    % at least a 4x4 cell
  1187.    45
  1188.     % The following screen algorithm is used by permission of the author.
  1189.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1190.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1191.     }
  1192.    bind
  1193.     % Determine whether we have lots of process colors.
  1194.     % If so, don't bother with color screening or gamma correction.
  1195.     % Also don't do gamma correction on very high-resolution devices.
  1196.     % (This should depend on dot gain, not resolution, but we don't
  1197.     % currently have a way to determine this.)
  1198.    currentdevice mark
  1199.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1200.    .dicttomark .getdeviceparams
  1201.    counttomark 2 idiv 1 sub { exch pop .min } repeat
  1202.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1203.     % Stack: doscreen dpi freq angle proc
  1204.     % Ghostscript currently doesn't use correct, per-plane halftones
  1205.     % unless setcolorscreen has been executed.  Since these are
  1206.     % computationally much more expensive than binary halftones,
  1207.     % we check to make sure they are really warranted, i.e., we have
  1208.     % a high-resolution CMYK device (i.e., not a display) with
  1209.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1210.    4 -1 roll 150 ge
  1211.     { /setcolorscreen where
  1212.        { pop //systemdict /COLORSCREEN known
  1213.       { COLORSCREEN }
  1214.       { 3 index }
  1215.      ifelse
  1216.      dup false ne
  1217.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1218.     % For really high-quality screening on printers, we need to
  1219.     % give each plane its own screen angle.  Unfortunately,
  1220.     % this currently has very large space and time costs.
  1221.         true eq        % true => different angles,
  1222.                 % 0 => same angles
  1223.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1224.          }
  1225.         if //setcolorscreen
  1226.       }
  1227.       { pop //setscreen    % false => single binary screen
  1228.       }
  1229.      ifelse
  1230.        }
  1231.        { //setscreen        % setcolorscreen not known
  1232.        }
  1233.       ifelse
  1234.     }
  1235.     { //setscreen            % not high resolution
  1236.     }
  1237.    ifelse
  1238. } bind def
  1239. /.sethiresscreen {    % <dpi> .sethiresscreen -
  1240.   .sethireshalftone
  1241.             % Stack: doscreen
  1242.     {    % Set the transfer function to lighten up the grays.
  1243.     % We correct at the high end so that very light grays
  1244.     % don't disappear completely if they darken <1 screen pixel.
  1245.     % Parameter values closer to 1 are better for devices with
  1246.     % less dot spreading; lower values are better with more spreading.
  1247.     % The value 0.8 is a compromise that will probably please no one!
  1248.     %
  1249.     % Because of a bug in FrameMaker, we have to accept operands
  1250.     % outside the valid range of [0..1].
  1251.       { dup dup 0.0 gt exch 1.0 lt and
  1252.      { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1253.         { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1254.           1 exch div 1 exch sub .min
  1255.         }
  1256.        if
  1257.      }
  1258.     if
  1259.       }
  1260.     }
  1261.     {    % Set the transfer function to the identity.
  1262.       0 array cvx        % Genoa CET won't accept a packed array!
  1263.     }
  1264.    ifelse settransfer
  1265.    /setstrokeadjust where { pop false setstrokeadjust } if
  1266.     % Increase fill adjustment so that we effectively use Adobe's
  1267.     % any-part-of-pixel rule.
  1268.    0.5 .setfilladjust
  1269. } bind def
  1270. % Set the default screen and BG/UCR.
  1271. /.setdefaultbgucr {
  1272.   systemdict /setblackgeneration known {
  1273.     { pop 0 } dup setblackgeneration setundercolorremoval
  1274.   } if
  1275. } bind def
  1276. /.useloresscreen {    % - .useloresscreen <bool>
  1277.     % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1278.   72 72 matrix defaultmatrix dtransform abs exch abs .min
  1279.   dup 150 lt //systemdict /DITHERPPI known not and
  1280. } bind def
  1281.  
  1282. % The following implementation uses LL2 extensions, but only in stopped
  1283. % contexts so that with LL1, the .set??reshalftone will be used.
  1284. %
  1285. %    - .getdefaulthalftone <halftonedict> true    if default found
  1286. %                  false            
  1287. /.getdefaulthalftone {
  1288.   % try the device to see if it has a default halftone
  1289.   { currentdevice /HalftoneDefault gsgetdeviceprop } stopped
  1290.   { pop pop false }        % no device property
  1291.   { dup type /dicttype eq { true } { pop false } ifelse }
  1292.   ifelse
  1293.   % stack: <halftonedict> true    if default found
  1294.   %         false          not found
  1295.   dup not
  1296.   { % device did not provide a default, try Resource
  1297.     pop { /Default /Halftone /findresource .systemvar exec } stopped 
  1298.     { pop pop false } { true } ifelse
  1299.   }
  1300.   if
  1301. } bind def
  1302.  
  1303. /.setdefaulthalftone {
  1304.   .getdefaulthalftone 
  1305.   { sethalftone }
  1306.   { % default not found
  1307.     .useloresscreen { .setloreshalftone } { .sethireshalftone pop } ifelse
  1308.   }
  1309.   ifelse
  1310. } bind def
  1311.  
  1312. /.setdefaultscreen {
  1313.   .useloresscreen { .setloresscreen } { .sethiresscreen } ifelse
  1314.   .setdefaultbgucr
  1315. } bind def
  1316.  
  1317. % Load the initialization files for optional features.
  1318. %% Replace 4 INITFILES
  1319. systemdict /INITFILES known
  1320.  { INITFILES { dup runlibfile VMDEBUG } forall
  1321.  }
  1322. if
  1323.  
  1324. % If Level 2 (or higher) functionality is implemented, enable it now.
  1325. /.setlanguagelevel where {
  1326.   pop 2 .setlanguagelevel
  1327.     % If the resource machinery is loaded, fix up some things now.
  1328.   /.fixresources where { pop .fixresources } if
  1329. } if
  1330. /ll3dict where {
  1331.   pop 3 .setlanguagelevel
  1332. } if
  1333.  
  1334. (END INITFILES) VMDEBUG
  1335.  
  1336. % Create a null font.  This is the initial font.
  1337. 8 dict dup begin
  1338.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1339.   /FontType 3 def
  1340.   /FontName () def
  1341.   /Encoding StandardEncoding def
  1342.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1343.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1344.   /PaintType 0 def        % shouldn't be needed!
  1345. end
  1346. /NullFont exch definefont setfont
  1347.  
  1348. % Define NullFont as the font.
  1349. /NullFont currentfont def
  1350.  
  1351. % Load initial fonts from FONTPATH directories, Fontmap file,
  1352. % and/or .getccfont as appropriate.
  1353. .loadinitialfonts
  1354.  
  1355. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1356. /undefinefont where {
  1357.   pop /NullFont undefinefont
  1358. } {
  1359.   FontDirectory /NullFont .undef
  1360. } ifelse
  1361.  
  1362. (END FONTS) VMDEBUG
  1363.  
  1364. % Restore the real definition of runlibfile.
  1365. /runlibfile /.runlibfile load def
  1366. currentdict /.runlibfile .undef
  1367.  
  1368. % Bind all the operators defined as procedures.
  1369. /.bindoperators        % binds operators in currentdict
  1370.  { % Temporarily disable the typecheck error.
  1371.    errordict /typecheck 2 copy get
  1372.    errordict /typecheck { pop } put    % pop the command
  1373.    currentdict
  1374.     { dup type /operatortype eq
  1375.        { % This might be a real operator, so bind might cause a typecheck,
  1376.      % but we've made the error a no-op temporarily.
  1377.      .bind        % do a real bind even if NOBIND is set
  1378.        }
  1379.       if pop pop
  1380.     } forall
  1381.    put
  1382.  } def
  1383. NOBIND DELAYBIND or not { .bindoperators } if
  1384.  
  1385. % Establish a default environment.
  1386.  
  1387. defaultdevice
  1388. % The following line used to skip setting of page size and resolution if
  1389. % NODISPLAY was selected.  We think this was only to save time and memory,
  1390. % and it is a bad idea because it prevents setting the resolution in this
  1391. % situation, which pstoedit (among other programs) relies on.
  1392. %DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1393. systemdict /DEVICEWIDTH known
  1394. systemdict /DEVICEHEIGHT known or
  1395. systemdict /DEVICEWIDTHPOINTS known or
  1396. systemdict /DEVICEHEIGHTPOINTS known or
  1397. systemdict /DEVICEXRESOLUTION known or
  1398. systemdict /DEVICEYRESOLUTION known or
  1399. systemdict /PAPERSIZE known or
  1400. not { (%END DEVICE) .skipeof } if
  1401. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1402. systemdict /PAPERSIZE known
  1403. systemdict /DEVICEWIDTH known not and
  1404. systemdict /DEVICEHEIGHT known not and
  1405. systemdict /DEVICEWIDTHPOINTS known not and
  1406. systemdict /DEVICEHEIGHTPOINTS known not and
  1407.  {    % Convert the paper size to device dimensions.
  1408.    true statusdict /.pagetypenames get
  1409.     { PAPERSIZE eq
  1410.        { PAPERSIZE load
  1411.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1412.          1 get /DEVICEHEIGHTPOINTS exch def
  1413.          pop false exit
  1414.        }
  1415.       if
  1416.     }
  1417.    forall
  1418.     { (Unknown paper size: ) print PAPERSIZE ==only (.) =
  1419.     }
  1420.    if
  1421.  }
  1422. if
  1423. % Adjust the device parameters per the command line.
  1424. % It is possible to specify resolution, pixel size, and page size;
  1425. % since any two of these determine the third, conflicts are possible.
  1426. % We simply pass them to .setdeviceparams and let it sort things out.
  1427.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1428.    .getdeviceparams .dicttomark begin
  1429.    mark
  1430.     % Check for resolution.
  1431.    /DEVICEXRESOLUTION where dup
  1432.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1433.    if
  1434.    /DEVICEYRESOLUTION where dup
  1435.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1436.    if
  1437.    or { /HWResolution HWResolution } if
  1438.     % Check for device sizes specified in pixels.
  1439.    /DEVICEWIDTH where dup
  1440.     { exch pop HWSize 0 DEVICEWIDTH put }
  1441.    if
  1442.    /DEVICEHEIGHT where dup
  1443.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1444.    if
  1445.    or { /HWSize HWSize } if
  1446.     % Check for device sizes specified in points.
  1447.    /DEVICEWIDTHPOINTS where dup
  1448.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1449.    if
  1450.    /DEVICEHEIGHTPOINTS where dup
  1451.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1452.    if
  1453.    or { /PageSize PageSize } if
  1454.     % Check whether any parameters were set.
  1455.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1456.    end
  1457. %END DEVICE
  1458. % Set any device properties defined on the command line.
  1459. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1460. systemdict /BufferSpace known
  1461. systemdict /MaxBitmap known not and
  1462.  { systemdict /MaxBitmap BufferSpace put
  1463.  } if
  1464. dup getdeviceprops
  1465. counttomark 2 idiv
  1466.  { systemdict 2 index known
  1467.     { pop dup load counttomark 2 roll }
  1468.     { pop pop }
  1469.    ifelse
  1470.  } repeat
  1471. counttomark dup 0 ne
  1472.  { 2 add -1 roll putdeviceprops }
  1473.  { pop pop }
  1474. ifelse
  1475. % If the initial device parameters are invalid, the setdevice may fail.
  1476. % Trap this and produce a reasonable error message.
  1477. { setdevice }        % does an erasepage
  1478. DEBUG { exec false } { .internalstopped } ifelse {
  1479.   (**** Unable to open the initial device, quitting.) = flush 1 .quit
  1480. } if
  1481.  
  1482. % If the media size is fixed, update the current page device dictionary.
  1483. FIXEDMEDIA
  1484. dup { pop systemdict /.currentpagedevice known } if
  1485. dup { pop .currentpagedevice exch pop } if
  1486. not { (%END MEDIA) .skipeof } if
  1487. currentpagedevice dup length dict .copydict
  1488. dup /Policies
  1489.     % Stack: <pagedevice> <pagedevice> /Policies
  1490. 1 index /InputAttributes
  1491. 2 copy get dup length dict .copydict
  1492.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1493.     %   /InputAttributes <inputattrs'>
  1494. dup 0 2 copy get dup length dict .copydict
  1495.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1496.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1497. dup /PageSize 7 index /PageSize get
  1498. put                % PageSize in 0
  1499. put                % 0 in InputAttributes
  1500. put                % InputAttributes in pagedevice
  1501. % Also change the page size policy so we don't get an error.
  1502.     % Stack: <pagedevice> <pagedevice> /Policies
  1503. 2 copy get dup length dict .copydict
  1504.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1505. dup /PageSize 7 put        % PageSize in Policies
  1506. put                % Policies in pagedevice
  1507. .setpagedevice
  1508. %END MEDIA
  1509. %END DISPLAYING
  1510.  
  1511. (END DEVICE) VMDEBUG
  1512.  
  1513. % Establish a default upper limit in the character cache,
  1514. % namely, enough room for a 18-point character at the resolution
  1515. % of the default device, or for a character consuming 1% of the
  1516. % maximum cache size, whichever is larger.
  1517. mark
  1518.     % Compute limit based on character size.
  1519.   18 dup dtransform
  1520.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1521.   exch abs cvi mul        % Y
  1522.     % Compute limit based on allocated space.
  1523.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1524.   .max dup 10 idiv exch
  1525. setcacheparams
  1526. % Conditionally disable the character cache.
  1527. NOCACHE { 0 setcachelimit } if
  1528.  
  1529. (END CONFIG) VMDEBUG
  1530.  
  1531. % Initialize graphics.
  1532.  
  1533. .setdefaultscreen
  1534. initgraphics
  1535.  
  1536. % The interpreter relies on there being at least 2 entries
  1537. % on the graphics stack.  Establish the second one now.
  1538. gsave
  1539.  
  1540. % Define some control sequences as no-ops.
  1541. % This is a hack to get around problems
  1542. % in some common PostScript-generating applications.
  1543. <04> cvn { } def        % Apple job separator
  1544. <0404> cvn { } def        % two of the same
  1545. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1546.                 % (UEL = ESC %-12345X)
  1547. <1b45> cvn { } def        % PJL reset prologue (ESC E)
  1548. <1b451b> cvn { } def        % PJL reset epilogue (ESC E + UEL)
  1549. <041b> cvn { } def        % MS Windows LaserJet 4 epilogue (^D + UEL)
  1550. (\001M) cvn            % TBCP initiator
  1551.  { currentfile /TBCPDecode filter cvx exec
  1552.  } bind def
  1553. /@PJL                % H-P job control
  1554.  { currentfile //=string readline { pop } if
  1555.  } bind def
  1556.  
  1557. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1558. .currentglobal true .setglobal
  1559. /SAFETY 2 dict
  1560.   dup /safe false put
  1561.   dup /tempfiles 10 dict readonly put
  1562. readonly def
  1563. .setglobal
  1564.  
  1565. % Convert a path name into a string suitable for filenameforall
  1566. % For example: (a\\b*?c) to (a\\\\b\\*\\?c)
  1567. /.makepathtemplate {    % str1 -- str2
  1568.    dup length dup add string 0    % result string up to twice the size
  1569.    0 1 4 index length 1 sub {
  1570.      3 index exch get
  1571.      dup 92 eq {        % \ -> \\
  1572.         2 index 2 index 92
  1573.         put
  1574.         exch 1 add exch
  1575.      } 
  1576.      if
  1577.      dup 42 eq {        % * -> \*
  1578.         2 index 2 index 92
  1579.         put
  1580.         exch 1 add exch
  1581.      } 
  1582.      if
  1583.      dup 63 eq {        % ? -> \?
  1584.         2 index 2 index 92
  1585.         put
  1586.         exch 1 add exch
  1587.      } 
  1588.      if
  1589.      2 index 2 index 3 -1 roll put 1 add
  1590.    } for
  1591.    0 exch getinterval exch pop
  1592. } bind def
  1593.  
  1594. /.locksafe {
  1595.   SAFETY /safe get not {
  1596.     <<
  1597.       /PermitFileReading [
  1598.         currentuserparams /PermitFileReading get aload pop
  1599.     { .makepathtemplate 
  1600.           dup .filenamedirseparator concatstrings (*) concatstrings 
  1601.       exch        % put string below this procedure
  1602.     }
  1603.         /LIBPATH .systemvar { 1 index exec } forall
  1604.         /FONTPATH .systemvar  { 1 index exec } forall
  1605.     currentsystemparams /GenericResourceDir get 1 index exec 
  1606.     currentsystemparams /FontResourceDir get exch exec
  1607.       ]
  1608.       /LockFilePermissions true
  1609.     >> setuserparams
  1610.   }
  1611.   if
  1612.   % Pretty much the same as "<< /.LockSafetyParams true >> setpagedevice"
  1613.   % but without some of the side effects.
  1614.   mark currentdevice null true mark /.LockSafetyParams true .putdeviceparamsonly
  1615.   counttomark 2 eq 
  1616.   { cleartomark }
  1617.   { cleartomark cleartomark pop pop pop
  1618.     /invalidaccess /.locksafe signalerror
  1619.   } ifelse
  1620.   //SAFETY /safe //true .forceput % overrides readonly
  1621. } .bind executeonly odef
  1622.  
  1623. /.setsafe
  1624. {
  1625.   SAFETY /safe get not {
  1626.     <<
  1627.       PARANOIDSAFER {        % only PARANOIDSAFER locks down reading files
  1628.         /PermitFileReading [ ]
  1629.       } if
  1630.       /PermitFileWriting [ ]
  1631.       /PermitFileControl [ ]
  1632.     >> setuserparams
  1633.   }
  1634.   if
  1635.   .locksafe
  1636. } .bind executeonly odef
  1637.  
  1638. /deletefile {
  1639.   count 1 lt {
  1640.     //deletefile /stackunderflow signalerror
  1641.   }
  1642.   if
  1643.   dup { deletefile } stopped {
  1644.     pop //deletefile $error /errorname get signalerror
  1645.   } {
  1646.     % deletefile succeeded. Remove from tempfile list if present
  1647.     //SAFETY /tempfiles get exch cvn 2 copy known {
  1648.       .forceundef
  1649.     } {
  1650.       pop pop
  1651.     }
  1652.     ifelse
  1653.   }
  1654.   ifelse
  1655. } .bind executeonly odef
  1656.  
  1657. % If a file is opened with .tempfile with SAFER not (yet) set,
  1658. % the file can be deleted later, even if SAFER is set.
  1659. /.tempfile {
  1660.   .tempfile    % filename file
  1661.   //SAFETY /tempfiles get 2 index true .forceput
  1662. } .bind executeonly odef
  1663.  
  1664. % If we are running in SAFER mode, lock things down
  1665. SAFER { .setsafe } if
  1666.  
  1667. % If we delayed binding, make it possible to do it later.
  1668. /.bindnow {
  1669.   //systemdict begin .bindoperators end
  1670.   % Temporarily disable the typecheck error.
  1671.   errordict /typecheck 2 copy get
  1672.   errordict /typecheck { pop } put    % pop the command
  1673.   0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1674.   //systemdict /.delaybind {} .forceput    % reclaim the space
  1675.   //systemdict /.bindnow .forceundef    % ditto
  1676.   put
  1677.   //systemdict /.forcedef .forceundef        % remove temptation
  1678.   //systemdict /.forceput .forceundef        % ditto
  1679.   //systemdict /.forceundef .forceundef        % ditto
  1680. } .bind odef
  1681.  
  1682. % Turn off array packing, since some PostScript code assumes that
  1683. % procedures are writable.
  1684. false setpacking
  1685.  
  1686. (END INIT) VMDEBUG
  1687.  
  1688. /.currentuserparams where {
  1689.   pop
  1690.     % Remove real user params from psuserparams.
  1691.   mark .currentuserparams counttomark 2 idiv {
  1692.     pop psuserparams exch undef
  1693.   } repeat pop
  1694.     % Update the copy of the user parameters.
  1695.   mark .currentuserparams counttomark 2 idiv {
  1696.     userparams 3 1 roll .forceput    % userparams is read-only
  1697.   } repeat pop
  1698.     % Turn on idiom recognition, if available.
  1699.   currentuserparams /IdiomRecognition known {
  1700.     /IdiomRecognition true .definepsuserparam
  1701.   } if
  1702.   psuserparams readonly pop
  1703.   systemdict /.definepsuserparam undef
  1704.     % Save a copy of userparams for use with save/restore
  1705.     % (and, if implemented, context switching).
  1706.   .currentglobal false .setglobal
  1707.      mark userparams { } forall .dicttomark readonly
  1708.      /userparams exch .forcedef        % systemdict is read-only
  1709.   .setglobal
  1710. } if
  1711. /.currentsystemparams where {
  1712.   pop
  1713.     % Remove real system params from pssystemparams.
  1714.   mark .currentsystemparams counttomark 2 idiv {
  1715.     pop pssystemparams exch .forceundef
  1716.   } repeat pop
  1717. } if
  1718.  
  1719. % Conditionally turn image interpolation on or off.
  1720. currentdict /INTERPOLATE known not { (%END INTERPOLATE) .skipeof } if
  1721.  
  1722. /.interpolate {
  1723.   dup /Interpolate .knownget not { //false } if
  1724.   /INTERPOLATE .systemvar ne {
  1725.     dup gcheck .currentglobal exch .setglobal
  1726.     exch dup length dict copy
  1727.     dup /Interpolate /INTERPOLATE .systemvar put
  1728.     exch .setglobal
  1729.   } if
  1730. } bind odef
  1731.  
  1732. /colorimage
  1733.   { /INTERPOLATE .systemvar
  1734.       { .currentglobal                    % w h bit [] {}...{} multi ncomp glob
  1735.         //false .setglobal
  1736.         9 dict begin                      % w h bit [] {}...{} multi ncomp glob
  1737.         2 index { 1 index 7 add } { 8 } ifelse
  1738.         copy gsave pop                    % preserve the arguments
  1739.         { 0 /DeviceGray 0 /DeviceRGB /DeviceCMYK }
  1740.         1 index get setcolorspace         % ... glob w h bit [] {}...{} multi ncomp
  1741.         {0 1 0 1 0 1 0 1}
  1742.         1 index 2 mul 0 exch              % ... glob w h bit [] {}...{} multi ncomp {0 1 ...} 0 2*ncomp
  1743.         getinterval /Decode exch def      % ... glob w h bit [] {}...{} multi ncomp
  1744.         exch dup                          % ... glob w h bit [] {}...{} ncomp multi multi
  1745.         /MultipleDataSources exch def     % ... glob w h bit [] {}...{} ncomp multi
  1746.         { array astore} { pop } ifelse    % ... glob w h bit [] [{}...{}]
  1747.         /DataSource exch def              % ... glob w h bit []
  1748.         /ImageMatrix exch def             % ... glob w h bit
  1749.         /BitsPerComponent exch def        % ... glob w h
  1750.         /Height exch def                  % ... glob w
  1751.         /Width exch def                   % ... glob 
  1752.         /ImageType 1 def
  1753.         /Interpolate //true def
  1754.         .setglobal currentdict end        % ... <<>>
  1755.         image grestore
  1756.         exch { 4 add } { 6 } ifelse
  1757.         { pop } repeat                    % -
  1758.       }
  1759.       { colorimage
  1760.       }
  1761.     ifelse
  1762.   } bind odef
  1763.  
  1764. /image
  1765.   { dup type /dicttype eq
  1766.       { dup /ImageType get 3 eq
  1767.           { .currentglobal //false .setglobal exch
  1768.             dup length dict copy begin .setglobal 
  1769.             /DataDict DataDict .interpolate def
  1770.             /MaskDict MaskDict .interpolate def
  1771.             currentdict end
  1772.           }
  1773.           { .interpolate 
  1774.           }
  1775.         ifelse
  1776.         image
  1777.       }
  1778.       { /INTERPOLATE .systemvar
  1779.           { .currentglobal //false .setglobal
  1780.             8 dict begin .setglobal
  1781.             /ImageType 1 def
  1782.             /DataSource 1 index def
  1783.             /ImageMatrix 2 index def
  1784.             /BitsPerComponent 3 index def
  1785.             /Decode {0 1} def
  1786.             /Height 4 index def
  1787.             /Width 5 index def
  1788.             /Interpolate //true def
  1789.             currentdict end
  1790.             gsave /DeviceGray setcolorspace image grestore
  1791.             5 { pop } repeat
  1792.           }
  1793.           { image
  1794.           }
  1795.         ifelse
  1796.       }
  1797.     ifelse
  1798.   } bind odef
  1799.  
  1800. /imagemask {
  1801.   dup type /dicttype eq {
  1802.     .interpolate imagemask
  1803.   } {
  1804.     /INTERPOLATE .systemvar {
  1805.       .currentglobal //false .setglobal
  1806.       8 dict begin .setglobal
  1807.       /ImageType 1 def
  1808.       /DataSource 1 index def
  1809.       /ImageMatrix 2 index def
  1810.       /BitsPerComponent 1 def
  1811.       2 index { {1 0} } { {0 1} } ifelse /Decode exch def
  1812.       /Height 4 index def
  1813.       /Width 5 index def
  1814.       /Interpolate //true def
  1815.       currentdict end imagemask 5 { pop } repeat
  1816.     } {
  1817.       imagemask
  1818.     } ifelse
  1819.   } ifelse
  1820. } bind odef
  1821.  
  1822. currentdict /.interpolate undef
  1823.  
  1824. %END INTERPOLATE
  1825.  
  1826. % Establish local VM as the default.
  1827. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1828. $error /.nosetlocal false put
  1829.  
  1830. (END GLOBAL) VMDEBUG
  1831.  
  1832. /.savelocalstate where {
  1833.     % If we might create new contexts, save away copies of all dictionaries
  1834.     % referenced from systemdict that are stored in local VM,
  1835.     % and also save a copy of the initial gstate.
  1836.   pop .savelocalstate
  1837. } {
  1838.     % If we're *not* running in a multi-context system and FAKEFONTS is
  1839.     % defined, add the fake fonts to LocalFontDirectory.
  1840.   .definefakefonts    % current VM is local
  1841. } ifelse
  1842.  
  1843. % Remove systemdict entries for things that have been bound in where used
  1844. % and that shouldn't be accessible by name, and close up systemdict.
  1845. currentdict /filterdict .undef
  1846. currentdict /.cidfonttypes .undef
  1847. currentdict /.colorrenderingtypes .undef
  1848. currentdict /.formtypes .undef
  1849. currentdict /.halftonetypes .undef
  1850. currentdict /.imagetypes .undef
  1851. currentdict /.imagemasktypes .undef
  1852. currentdict /.patterntypes .undef
  1853. currentdict /.shadingtypes .undef
  1854. currentdict /.wheredict .undef
  1855. end
  1856.  
  1857. % Clean up VM, and enable GC.
  1858. /vmreclaim where
  1859.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1860.  } if
  1861. DELAYBIND not {
  1862.   systemdict /.forcedef .undef        % remove temptation
  1863.   systemdict /.forceput .undef        % ditto
  1864.   systemdict /.forceundef .undef    % ditto
  1865. } if
  1866. WRITESYSTEMDICT not { systemdict readonly pop } if
  1867.  
  1868. (END GC) VMDEBUG
  1869.  
  1870. % The Adobe AGM_Core used by Illustrator 9 has some code that breaks
  1871. % if the 'product' is not (Adobe PostScript Parser). A bug has been
  1872. % submitted to Adobe since this also fails with Acrobat Distiller.
  1873. % As a temporary work around, the following HACK will work for
  1874. % devices without spot color support. Once Ghostscript can
  1875. % support DeviceN and spot color separations this will need to
  1876. % be 'true' in some cases.
  1877. userdict /AGM_preserve_spots false put
  1878.  
  1879. % The interpreter will run the initial procedure (start).
  1880.